package com.dyz.LeetCodeforSwordFingerOffer;

public class Fib10 {
    //思路：先取模，在求和，如果先求和在取模容易超出int（8位） long（64）范围
    public int fib(int n) {
        //f(n) = f(n-1) + f(n-2)
        if(n==0){return 0;}
        if(n==1){return 1;}
        int first = 0;
        int second = 1;
        int result = 0;
        for(int i = 2; i<=n;i++){
            result = (first +second)%1000000007;
            first = second;
            second = result;
        }
        return result ;
    }
}
